<?

//Initiate Authenticate
SecurityRedirect ();

//initiate Vars 
define("PRIMARY_KEY","nobkt");
$KEY[]         = array("PRIMARY_KEY"=>PRIMARY_KEY);
$FileName      = "ais_report_journaltrans_trans_list.php";
$FileTemplate  = "ais_report_journaltrans_trans_list.html";

$PageSize      = 10 ;
$TableName     = "ais_memorial";


//************ FORM ACTION **************

//Initiate Database Table For Search;
$FCode = GetParam("CodeSearch","");

//******* DATABASE FORM QUERY ***********
$SQL = "SELECT * FROM `$TableName` ";
$SQLCount = "SELECT count(*) FROM `$TableName` ";
$WHERE  = " urut=001 ";
$FieldName = GetParam("FieldName","");
$TransType = GetParam("TransType","");

$FMonth  = GetParam("FMonth","");
$FYear    = GetParam("FYear","");
$WHERE   .= BuildCondition ($TransType);
$WHERE   .= " AND YEAR(tglbkt)=$FYear AND MONTH(tglbkt)=$FMonth ";

if ($FCode) 
	 $WHERE .= " AND  nobkt like '".$FCode."%'";

	if (strlen($WHERE))	$WHERE = " WHERE ".$WHERE;
	else $WHERE = " WHERE 1";

$SQL = $SQL.$WHERE;
$SQL .= " ORDER BY nobkt ";
$SQLCount = $SQLCount.$WHERE;

//******* SHOW FORM CONTENT *********
$PageNum = 1;
$RecCnt = $DBConnection->dbc->get_var($SQLCount) ; 

if (GetParam("PageNum","")) $PageNum  = GetParam("PageNum","");

$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate($MOD_TEMPLATE_DIR."/".$FileTemplate);
$TBS->MergeBlock("bln",$KEY);
$TBS->MergeBlock("blg",$DBMysql,$SQL,$PageSize,$PageNum,$RecCnt);
$TBS->MergeNavigationBar('nv',array('size'=>10,'pos'=>'centred'),$PageNum,$RecCnt,$PageSize) ; 
$TBS->Show();

function BuildCondition ($no) {
	$row_number = explode(",",$no);
	//print $row_number[0];
	for ($x=0;$x<count($row_number);$x++) {
		if (strlen($WHERE)) $WHERE .= " OR nobkt like '$row_number[$x]%' ";
		else $WHERE = " nobkt like '$row_number[$x]%' ";
	}
	if (strlen($WHERE)) $WHERE = " AND ".$WHERE;
	return $WHERE;
}

function DeleteRecord ($sequence_name,$PageSize) {
	global $DBConnection,$FileName;	
	for ($x=1;$x<=$PageSize;$x++) {		
		if (GetParam($sequence_name.$x,""))	{
			$DBConnection->Delete("tblcustomer",$sequence_name.$x);
	    }
	}
	header("Location: $FileName");
	exit;	
	
}

?>